// pages/personal/personal.js
import request from '../../utils/request';

let startY = 0;
let moveY = 0;
let moveDistace = 0;

Page({

  /**
   * 页面的初始数据
   */
  data: {
    coverTransforom : 'translateY(0rpx)',
    convertTransition: '',
    userInfo:{},
    recentPlayList:[]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    // let userInfo = wx.getStorageSync('userInfo');
    // console.log(userInfo);
    // if(userInfo){
    //   this.setData({userInfo:JSON.parse(userInfo)})
    // }

  },

  async getUserRecentPlayList(userId){
    let recentPlayListData = await request('/user/record',{uid:61924989,type:0});
    console.log(recentPlayListData)
    let recentPlayList = recentPlayListData.allData.splice(0,10).map(
      item => {
        item.id = item.song.id 
        return item
    });
    this.setData({
      recentPlayList: recentPlayList
    })
  },

  handleTouchStart: function(event){
    startY  = event.touches[0].clientY;
  },

  bindtouchMove: function(event){
    moveY  = event.touches[0].clientY;
    moveDistace =  moveY - startY;
    console.log("moveDistace",moveDistace);
    if(moveDistace < 0 || moveDistace >= 80){
        return;
    }
    this.setData({
      coverTransforom: `translateY(${moveDistace}rpx)`,
      convertTransition: ''
    })
  },

  bindtouchEnd: function(){
    this.setData({
      coverTransforom: `translateY(0rpx)`,
      convertTransition: `transform 1s linear`
    })
  },



  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    let userInfo = wx.getStorageSync('userInfo');
    console.log(userInfo);
    if(userInfo){
      this.setData({userInfo:JSON.parse(userInfo)})
    }
    this.getUserRecentPlayList(this.data.userInfo.userId);
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})